package com.qk.controller;

import com.qk.PageResult;
import com.qk.common.Result;
import com.qk.entity.Activity;
import com.qk.service.ActivityService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RequestMapping("/activities")
@RestController
public class ActivityController {
    @Autowired
    private ActivityService activityService;

    //1. 活动列表查询
    @GetMapping
    public Result getList(Integer channel,Integer type,Integer status,
                          @RequestParam(defaultValue = "1") Integer page,
                          @RequestParam(defaultValue = "10") Integer pageSize){
        log.info("活动列表查询请求参数:channel={},type={},status={},page={},pageSize={}",channel,type,status,page,pageSize);
        PageResult<Activity> pageResult=activityService.getList(channel,type,status,page,pageSize);
        return Result.success(pageResult);
    }


    //2. 删除活动
    @DeleteMapping("/{id}")
    public Result deleteById(@PathVariable Integer id){
        log.info("删除活动请求参数:id={}",id);
        activityService.deleteById(id);
        return Result.success();
    }

    //3. 添加活动
    @PostMapping
    public Result addActivity(@RequestBody Activity activity){
        log.info("添加活动请求参数:{}",activity);
        activityService.addActivity(activity);
        return Result.success();
    }

    //4. 根据ID查询
    @GetMapping("/{id}")
    public Result getActivityById(@PathVariable Integer id){
        log.info("查询-id={}",id);
        Activity activity= activityService.getById(id);
        return Result.success(activity);
    }

    //5. 修改活动
    @PutMapping
    public Result updateActivityById(@RequestBody Activity activity){
        log.info("修改活动:{}",activity);
        activityService.updateActivityById(activity);
        return Result.success();
    }

    //6. 查询指定类型的活动
    @GetMapping("/type/{type}")
    public Result getActivityByType(@PathVariable Integer type){
        log.info("查询指定类型的活动:{}",type);
        List<Activity> list=activityService.getActivityByType(type);
        return Result.success(list);
    }
}
